<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>信审驳回意见</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
		<form id="formSet1">
			<div class="fieldset1 tabel_col clearFix">
				<div class="fieldBox col_100">
					<div class="sqPanel">
		                <div class="sqPanel_head inL">
		                    <div class="btnsBox inLC">
		                        <span id="addBtn" class="sq-button sq-button-round">添加</span>
		                        <span id="delBtn" class="sq-button sq-button-round">删除</span>
		                        <span id="preview" class="sq-button sq-button-round">预览</span>
		                    </div>
		                    <span>驳回意见</span>
		                </div>
		                <div class="sqPanel_body">
		                    <div id="ligergrid_rejectOpn" class="sq-grid"></div>
		                </div>
					</div>
				</div>
			</div>
		</form>
	</div>
</div>

<script type="text/javascript">
var _projectId = '${projectId}';//项目ID
var _proIntId = '${proIntId}';//流程ID
var _taskId = '${taskId}';//任务ID
var _taskDefKey = '${taskDefKey}';//任务定义KEY
var _taskNm = '${taskNm}';//任务定义名称
var rejectOpnGrid;
var _capPayId = '${capPayId}';//付款信息ID
var _bookTypCd = '${bookTypCd}';//台账类型
var _opinionTypeCd = '${opinionTypeCd}';//驳回意见类型

var isCanCilckPreview = 0;

$(function(){
	$('#formSet1').ligerForm({
        validate : true
	});
	
	initRejectOpnGrid();
	
	$("#addBtn").click(function (event) {
		rejectOpnGrid.addRow({
			oneLevelId: '',
			twoLevelId: '',
			threeLevelId: '',
			remark: ''
        });
    });
	$("#delBtn").click(function (event) {
        //页面删除后必须点击保存才会维护到数据库中!!!!!!!!!!!!!!!
        //默认设置点击保存按钮???????????????????????
        var selectedRows = rejectOpnGrid.getSelectedRows();
        if(selectedRows.length==0){
        	top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning" });
        	return;
        }
        rejectOpnGrid.deleteSelectedRow();
    	/* top.$.ligerDialog.confirm("确认删除选中项吗?", function (flag) {
    		if(!flag){
    			return;
    		}else{
		        rejectOpnGrid.deleteSelectedRow();
		        //save();
    		}
    	}); */
    });
	$('#preview').on('click', function(event) {
		if(isCanCilckPreview==1){
	        event.preventDefault();
	        SQ.previewGrid_s('ligergrid_rejectOpn'); //参数是grid的ID
		}else{
			top.$.ligerDialog.SQalert({content: "请先保存意见!" , SQ_type: "warning" });
	        return;
		}
    });
})
//定义父级调用事件
frameElement.dialog.onOk = function () {
     save();
}
           
frameElement.dialog.onCancel = function () {
     frameElement.dialog.close();
}

function save(){
	var form = liger.get("formSet1");
    if (!form.valid()) {
    	top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
        return false;
    }
    var data = form.getData();
    data["projectId"] = _projectId;
    data["capPayId"] = _capPayId;
    data["proIntId"] = _proIntId
    data["taskId"] = _taskId;
    data["taskDefKey"] = _taskDefKey;
    data["taskNm"] = _taskNm;
    data["opinionTypeCd"] = _opinionTypeCd; //驳回意见类型
    data["bookTypCd"] = _bookTypCd; //台账类型
    data["opinionDetailJSON"] = JSON.stringify(rejectOpnGrid.getData());
    
    var url = '<%=path%>/audit/audRejectOpinion/add.do';
    var wait_dialog;
    $.ajax({
		type: 'post',
		dataType:'json',
		data:data,
		url: url,
		beforeSend: function(){
	          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	     },
		success:function(msg){
			 wait_dialog.close();
			 if(msg.success == 1){
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
				 if(msg.data){
					 $("#rejectOpnId").val(msg.data);
				 }
				 rejectOpnGrid.reload();
				 //frameElement.dialog.close();
				 isCanCilckPreview = 1;
			 }else{
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
			 }
		}
	});
}
var oneLevelListJSON = [];//一级名称
var twoLevelListJSON = [];//二级名称
var threeLevelListJSON = [];//三级名称

function initRejectOpnGrid(){
	rejectOpnGrid = $("#ligergrid_rejectOpn").ligerGrid({
        url: '<%=path%>/audit/audRejectOpinion/initList.do',
        method: 'get',
        parms:{
        	proIntId:_proIntId,
        	bookTypCd:_bookTypCd
        },
        columns: [
            {display: '一级名称', name: 'oneLevelId', minWidth: 100,
                editor: {
                	type: 'select',
                    data: oneLevelListJSON,
                    valueField: 'id',
                    textField: 'rsnDesc',
                },
                valueField: 'oneLevelId',
                textField: 'oneLevelRsnDesc',
                render: function (item) {
                    return item.oneLevelRsnDesc;
                }
            },
            {display: '二级名称', name: 'twoLevelId', minWidth: 100,
                editor: {
                    type: 'select',
                    data: twoLevelListJSON,
                    valueField: 'id',
                    textField: 'rsnDesc'
                },
                valueField: 'twoLevelId',
                textField: 'twoLevelRsnDesc',
                render: function (item) {
                    return item.twoLevelRsnDesc;
                }
            },
            {display: '三级名称', name: 'threeLevelId', minWidth: 100,
                editor: {
                	type: 'combobox',
                    isShowCheckBox: true,
                    isMultiSelect: true,
                    data: threeLevelListJSON,
                    valueField: 'id',
                    textField: 'rsnDesc'
                },
                valueField: 'threeLevelId',
                textField: 'threeLevelRsnDesc',
                render: function (item) {
                    return item.threeLevelRsnDesc;
                }
            },
            {display: '备注', name: 'remark', minWidth: 250, editor: {type: 'text'} },
        ],
        onBeforeEdit: function (e) {
        	if (e.column.columnname == "oneLevelId") {//一级名称
                getOneLevelListJSON(e);
                e.column.editor.data=oneLevelListJSON;
            }
            if (e.column.columnname == "twoLevelId") {//二级名称
                getTwoLevelListJSON(e.record.oneLevelId);
                e.column.editor.data=twoLevelListJSON;
            }
            if (e.column.columnname == "threeLevelId") {//三级名称
                getThreeLevelListJSON(e.record.twoLevelId);
                e.column.editor.data=threeLevelListJSON;
            }
        },
        onBeforeSubmitEdit: function (e) {
        	if (e.selected && e.column.columnname == "oneLevelId") {
                e.record.twoLevelId ="";
                e.record.twoLevelRsnDesc ="";
                e.record.threeLevelId = "";
                e.record.threeLevelRsnDesc = "";
            }
            if (e.selected && e.column.columnname == "twoLevelId") {
                e.record.threeLevelId = "";
                e.record.threeLevelRsnDesc = "";
            }
        },
        pageSize:100,
        usePagerOnLessPagesize: false,
        root: 'rows',
        record: 'total',
        hideLoadButton: true,
        width: '90%',
        height: 300,
        heightDiff: -2,
        enabledEdit: true,
        isScroll: false,
        checkbox: true,
        rownumbers: true,
        allowUnSelectRow: true,
        alternatingRow: false,
        enabledSort:false
    });
}
//获取一级意见数据
function getOneLevelListJSON(e){
	if(oneLevelListJSON&&oneLevelListJSON.length>0){
        return;
    }
	$.ajax({
		type: 'post',
		dataType:'json',
		async: false,
		data:{
			pid:AuditConstant.SYS_FLOW_REJ_RSN_PID,
			rsnTypCd:_opinionTypeCd
		},
		url: '<%=path%>/audit/audRejectOpinion/getRejOpnJSON.do',
		beforeSend: function () {
            wait_dialog = $.ligerDialog.SQalert({
                content: LogUtils.LOG_CMM_DATA_LOADING,
                SQ_type: "waitting"
            });
        },
		success:function(msg){
			wait_dialog.close();
			if(msg.success == 1){
				oneLevelListJSON=msg.data;
			}
		}
	});
}
//获取二级意见数据(参数:一级ID)
function getTwoLevelListJSON(oneLevelId){
	if(!oneLevelId){
        top.$.ligerDialog.SQalert({content: "请先选择一级意见", SQ_type: "warning"});
        return;
    }
	$.ajax({
		type: 'post',
		dataType:'json',
		async: false,
		data:{
			pid:oneLevelId,
			rsnTypCd:_opinionTypeCd
		},
		url: '<%=path%>/audit/audRejectOpinion/getRejOpnJSON.do',
		success:function(msg){
			if(msg.success == 1){
				twoLevelListJSON=msg.data;
			}
		}
	});
}
//获取三级意见数据(参数:二级ID)
function getThreeLevelListJSON(twoLevelId){
	if(!twoLevelId){
        top.$.ligerDialog.SQalert({content: "请先选择二级意见", SQ_type: "warning"});
        return;
    }
	$.ajax({
		type: 'post',
		dataType:'json',
		async: false,
		data:{
			pid:twoLevelId,
			rsnTypCd:_opinionTypeCd
		},
		url: '<%=path%>/audit/audRejectOpinion/getRejOpnJSON.do',
		success:function(msg){
			if(msg.success == 1){
				threeLevelListJSON=msg.data;
			}
		}
	});
}
</script>

</body>
</html>
